# Contributor: Valery Kartel <valery.kartel@gmail.com>
# Maintainer: Valery Kartel <valery.kartel@gmail.com>
pkgname=capstone
pkgver=5.0.3
pkgrel=0
pkgdesc="The Ultimate Disassembler"
url="https://www.capstone-engine.org"
arch="all"
license="BSD-3-Clause-Clear"
depends_dev="$pkgname"
makedepends="bash py3-setuptools cython python3-dev"
subpackages="$pkgname-static $pkgname-dev py3-$pkgname-pyc py3-${pkgname}:_py3 cstool"
source="$pkgname-$pkgver.tar.gz::https://github.com/aquynh/capstone/archive/$pkgver.tar.gz
	fix-python-binding-test-patch.patch
	py-path-fix.patch
	"

build() {
	export CFLAGS="$CFLAGS -O2 -flto=auto -ffat-lto-objects"
	make
	cd bindings/python
	python3 setup.py build
}

check() {
	make check

	# The `make check` doesn't run the Python binding tests.
	cd bindings/python
	PYTHONPATH="$(pwd)" make check
}

package() {
	make PREFIX=/usr DESTDIR="$pkgdir" install

	cd bindings/python
	python3 setup.py install --skip-build --root="$pkgdir"

	rm -rf "$pkgdir"/usr/lib/python3*/site-packages/capstone/lib
	rm -rf "$pkgdir"/usr/lib/python3*/site-packages/capstone/include
}

_py3() {
	pkgdesc="$pkgdesc (for python3)"
	depends="py3-setuptools capstone"

	amove usr/lib/python*
}

cstool() {
	pkgdesc="cstool for capstone disassembler"

	amove usr/bin/cstool
}

sha512sums="
2fd3194dd37065e6091d208c7670b12c0ca6872931eef794bd6b2dd624601c843e8ee6c5714eae0372e394e91a9bc1e4de7dfea6b1087542dd461226569101de  capstone-5.0.3.tar.gz
481629f39c901f4a53e0d1ea27573a87cfa200d48e5acebef6e87d2d26879403ffc3fd38ab9a63d556087d10320c204844f647bb0000627cc103c71d70f81bd1  fix-python-binding-test-patch.patch
93a28193a86ac2e7cd7d4081b4dc962c70d8898d2ed4d22b0760f2f4966f12204e8f6919f199a630b4fe4676df98d593d9adc79870f61e6343c93bdf88fe46c3  py-path-fix.patch
"
